<template>
	<view class="page-circle-publish-list">
		<u-navbar :is-back="true" :border-bottom="false" title-bold :title="title" title-color="#000" title-size="36rpx"
		 :title-bold="true">
			<view class="u-padding-right-30" slot="right" @click="goPublish()">
				添加
			</view>
		</u-navbar>
		<view class="list-warp u-padding-left-30 u-padding-right-30">
			<block v-for="(item,index) in list">
				<leftImgRightText :item="item" :isDel="true" @del="del" @goDeviceDetail="goDeviceDetail"></leftImgRightText>
				<u-line color="#ebebeb" v-if="list.length != (index+1)"></u-line>
			</block>
		</view>
		<u-modal v-model="show" content="确定删除吗？" :show-cancel-button="true" @cancel="cancel"
		@confirm="confirm"></u-modal>
	</view>
</template>

<script>
	import { commonGet } from "@/api/commonapi.js"
	import leftImgRightText from "@/components/common/left-img-right-text.vue"
	export default {
		components:{
			leftImgRightText
		},
		data() {
			return {
				list:[],
				show:false,
				id:"",
				title:"",
				cmdDel:""
			}
		},
		onLoad(options) {
			console.log(options);
			this.title = options.title
			this.cmdDel = options.cmdDel
			this.getList(options.cmdList)
		},
		methods: {
			goPublish(){
				switch(this.title){
					case '工程圈': this.$u.route('/pages/circle/circle-publish/circle-publish'); break;
					case '设备租售': this.$u.route('/pages/HomeLnner/add-device/add-device'); break;
					case '我的上传': this.$u.route('/pages/HomeLnner/add-upload/add-upload');
				}
			},
			getList(cmdList){
				let _this = this
				let query = {
					ak:_this.$store.state.token,
					cmd:cmdList,
					para:JSON.stringify({
						pageindex: 1,
						pagesize: 10
					})
				}
				commonGet(query,({Data})=>{
					console.log('----->',Data)
					_this.list = Data.Data
				})
			},
			del(item){
				this.show = true
				this.id=item.id
			},
			confirm(){
				let _this = this
				let query = {
					ak:_this.$store.state.token,
					cmd:_this.cmdDel,
					para:JSON.stringify({
						id: _this.id,
					})
				}
				commonGet(query,({Message})=>{
					console.log('----->',Message)
					if(Message == '操作成功！'){
						_this.list.find((item,index)=>{
							if(item.id == _this.id){
								_this.list.splice(index,1)
							}
						})
					}
				})
			},
			cancel(){},
			goDeviceDetail(item){
				switch (this.title){
					case '工程圈':this.$u.route('/pages/circle/circle-detail/circle-detail', {id: item.id});break;
					case '设备租售':this.$u.route('/pages/HomeLnner/DeviceDetails/DeviceDetails', {id: item.id});break;
					case '我的上传':this.$u.route('/pages/circle/circle-detail/circle-detail', {id: item.id});
				}
			}
		}
	}
</script>

<style>

</style>
